package com.machinetest;

import com.machinetest.entity.Staff;
import com.machinetest.utils.FileUtils;
import com.alibaba.fastjson.JSONArray;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Yancy
 */
public class Main {
  public static void main(String[] args) {

    String path = Main.class.getClassLoader().getResource("data1.json").getPath();
    String s = FileUtils.readJsonFile(path);
    JSONArray jsonArray= JSONArray.parseArray(s);

    List<Staff> staffList1 =new ArrayList<Staff>();
    List<Staff> staffList6 =new ArrayList<Staff>();
    List<Staff> staffJson = new ArrayList<>();
    for (int i =0;i<jsonArray.size();i++){
      int code = jsonArray.getJSONObject(i).getInteger("code");
      String name = jsonArray.getJSONObject(i).getString("name");
      String postion = jsonArray.getJSONObject(i).getString("postion");
      Integer supCode = jsonArray.getJSONObject(i).getInteger("superior_code");
      Staff staffTeam = new Staff();
      staffTeam.setCode(code);
      staffTeam.setName(name);
      staffTeam.setPostion(postion);
      staffTeam.setSuperior_code(supCode);
      if(supCode != null){
        if(supCode == 1){
          staffList1.add(staffTeam);
        }else if(supCode == 6){
          staffList6.add(staffTeam);
        }
      }else {
        if(code==1){
          staffTeam.setTeam(staffList1);
          staffJson.add(staffTeam);
        }else if(code==6){
          staffTeam.setTeam(staffList6);
          staffJson.add(staffTeam);
        }
      }

    }
    System.out.println(staffJson);

  }
}
